using System;
using System.Collections.Generic;
using System.Text;
using SideShow.Events;
using SideShow.Contents;
using System.IO;
using Serialization;
using SideShow.Channel.Messages;

namespace SideShow.Channel
{
    public class PocketPCClientChannel : PocketPCChannelBase, IClientChannel
    {
        private IServerChannel _channel;

        public PocketPCClientChannel(IServerChannel channel)
        {
            _channel = channel;
        }

        protected override void OnDataReceived(Message msg)
        {
            if (msg is AddApplicationMessage)
            {
                SideShowApplication app = ((AddApplicationMessage)msg).Application;
                _channel.AddApplication(app);
            }
            else if (msg is RemoveApplicationMessage)
            {
                Guid id = ((RemoveApplicationMessage)msg).ApplicationId;
                _channel.RemoveApplication(id);
            }
            else if (msg is AddContentMessage)
            {
                AddContentMessage acm = (AddContentMessage)msg;
                _channel.AddContent(acm.ApplicationId, acm.EndpointId, acm.Content);
            }
            else if (msg is RemoveContentMessage)
            {
                RemoveContentMessage rcm = (RemoveContentMessage)msg;
                _channel.RemoveContent(rcm.ApplicationId, rcm.EndpointId, rcm.ContentId);
            }
            else if (msg is InitializeMessage)
            {
                _channel.Initialize();
            }
            else if (msg is DeinitializeMessage)
            {
                _channel.Deinitialize();
            }
        }

                
        #region IClientChannel Members

        public void PostEvent(SideShow.Events.SideShowEvent e)
        {
            Send(new PostEventMessage(e));
        }

        #endregion
    }
}
